#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;
        if (nums.size() == 1)
            return 0;
        while (left <= right)
        {
            int mid = left + (right - left) / 2;
            if (mid + 1 < nums.size() && mid - 1 >= 0 && nums[mid] > nums[mid - 1] && nums[mid] > nums[mid + 1]) return mid;
            else if (mid - 1 < 0 && mid + 1 < nums.size() && nums[mid] > nums[mid + 1]) return mid;
            else if (mid + 1 == nums.size() && mid - 1 >= 0 && nums[mid] > nums[mid - 1]) return mid;
            else if (mid + 1 < nums.size() && nums[mid] < nums[mid + 1]) left = mid + 1;
            else right = mid - 1;
        }
        return right;
    }
};